﻿using Microsoft.EntityFrameworkCore.Migrations;
using TiaoTaoHelper.Wtm.Units.EFCore;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 访客中心流程表绑定微信用户更改为系统用户 : TransactionalMigration
    {
        /// <inheritdoc />
        protected override void UpWithTransaction(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysVisitorRecordRequestBill_SysWechatUser_WechatUserId",
                table: "SysVisitorRecordRequestBill");

            migrationBuilder.RenameColumn(
                name: "WechatUserId",
                table: "SysVisitorRecordRequestBill",
                newName: "UserId");

            migrationBuilder.RenameIndex(
                name: "IX_SysVisitorRecordRequestBill_WechatUserId",
                table: "SysVisitorRecordRequestBill",
                newName: "IX_SysVisitorRecordRequestBill_UserId");

            migrationBuilder.CreateIndex(
                name: "IX_SysVisitorRecordRequestBill_IdCardBackPhotoId",
                table: "SysVisitorRecordRequestBill",
                column: "IdCardBackPhotoId");

            migrationBuilder.CreateIndex(
                name: "IX_SysVisitorInformation_IdCardBackPhotoId",
                table: "SysVisitorInformation",
                column: "IdCardBackPhotoId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysVisitorInformation_FileAttachments_IdCardBackPhotoId",
                table: "SysVisitorInformation",
                column: "IdCardBackPhotoId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_SysVisitorRecordRequestBill_FileAttachments_IdCardBackPhotoId",
                table: "SysVisitorRecordRequestBill",
                column: "IdCardBackPhotoId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_SysVisitorRecordRequestBill_FrameworkUsers_UserId",
                table: "SysVisitorRecordRequestBill",
                column: "UserId",
                principalTable: "FrameworkUsers",
                principalColumn: "ID");
        }

        /// <inheritdoc />
        protected override void DownWithTransaction(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysVisitorInformation_FileAttachments_IdCardBackPhotoId",
                table: "SysVisitorInformation");

            migrationBuilder.DropForeignKey(
                name: "FK_SysVisitorRecordRequestBill_FileAttachments_IdCardBackPhotoId",
                table: "SysVisitorRecordRequestBill");

            migrationBuilder.DropForeignKey(
                name: "FK_SysVisitorRecordRequestBill_FrameworkUsers_UserId",
                table: "SysVisitorRecordRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysVisitorRecordRequestBill_IdCardBackPhotoId",
                table: "SysVisitorRecordRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysVisitorInformation_IdCardBackPhotoId",
                table: "SysVisitorInformation");

            migrationBuilder.RenameColumn(
                name: "UserId",
                table: "SysVisitorRecordRequestBill",
                newName: "WechatUserId");

            migrationBuilder.RenameIndex(
                name: "IX_SysVisitorRecordRequestBill_UserId",
                table: "SysVisitorRecordRequestBill",
                newName: "IX_SysVisitorRecordRequestBill_WechatUserId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysVisitorRecordRequestBill_SysWechatUser_WechatUserId",
                table: "SysVisitorRecordRequestBill",
                column: "WechatUserId",
                principalTable: "SysWechatUser",
                principalColumn: "ID");
        }
    }
}
